﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using DLL;
using BLL;
using System.Data;

namespace WebApplication2
{
    public partial class WebForm7 : System.Web.UI.Page
    {
        BLLShort bl = new BLLShort();
        //ShortCarShare sc = new ShortCarShare();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Info();
            }
            //城市选择
            SelectListCity.DataSource = LongSortBLL.SearchCity();
            SelectListCity.DataTextField = "CtName";
            SelectListCity.DataValueField = "CtID";
            SelectListCity.DataBind();
        }

        public void Info()
        {
            string id= Request.QueryString["id"];
            if (id != null)
            {
                bl.NumberApp(id);
            }
            if (id != null)
            {
                DataTable dt = bl.DataShort(id);
                //信息绑定
                labSgocity.Text = dt.Rows[0]["SGoCity"].ToString();
                LabelSDesitionation.Text = dt.Rows[0]["SDesitionation"].ToString();//目的城市地址
                LabelSPass.Text = dt.Rows[0]["SPass"].ToString();//途径城市
                LabelSGoDate.Text = dt.Rows[0]["SGoDate"].ToString();//出发日期
                LabelSGoTime.Text = dt.Rows[0]["SGoTime"].ToString();//出发时间
               // LabelSDesitionation.Text = dt.Rows[0][""].ToString();//申请人数
                LabelSContain.Text = dt.Rows[0]["SContain"].ToString();//容纳人数
                LabelSCarType.Text = dt.Rows[0]["SCarType"].ToString();//车型
                //LabelSDesitionation.Text = dt.Rows[0][""].ToString();//加入人数
                LabelSCost.Text = dt.Rows[0]["SCost"].ToString();//费用
                LabelSStatus.Text = dt.Rows[0]["SStatus"].ToString();//短途拼车状态
                LabelSCWord.Text = dt.Rows[0]["SCWord"].ToString();//车主留言
                LabelSBPeople.Text = dt.Rows[0]["SBPeople"].ToString();//浏览人数
                LabelSPTime.Text = dt.Rows[0]["SPTime"].ToString();//发布时间
                LabelUserID.Text = dt.Rows[0]["UserID"].ToString();//发布人手机

            }
            
        }
        protected void BtnSdd_Click(object sender, EventArgs e)
        {
            if (txtaddress1.Text.Length == 0)
            {
                Label1.Text = "不能为空！";
                return;
            }
            if (txtaddress2.Text.Length == 0)
            {
                Label2.Text = "不能为空！";
                return;
            }
            string SGoCity = txtaddress1.Text.Trim();
            string SDesitionation = txtaddress2.Text.Trim();
            Response.Redirect($"Commuting-SonTwo.aspx?SGoCity={SGoCity}&&SDesitionation={SDesitionation}");

        }

        //发布上下班拼车
        protected void ButRelease_Click(object sender, EventArgs e)
        {
            if (start.Text.Length != 0 && end.Text.Length != 0 &&txtModel.Text.Length!=0)
            {
                ShortCarShare sc = new ShortCarShare();
                //string str = ",";
                string strT = ":";
                string day= $"{Request.Form["daySelect"].ToString()}";
                string time = $"{Request.Form["timeSelect"].ToString()}";
                string minute = $"{Request.Form["minuteSelect"].ToString()}";

                sc.UserID = "13558365701";
                sc.SPType = "车主";
                sc.SStatus = "等待中";
                sc.SPTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                sc.SGoCity = start.Text.Trim();
                sc.SDesitionation = end.Text.Trim();
                //sc.SPass = TextBox3.Text += str += TextBox4.Text += str += TextBox5.Text += str += TextBox6.Text;
                sc.SPass = TextBox3.Text += TextBox4.Text += TextBox5.Text += TextBox6.Text;
                sc.SReturn = $"{Request.Form["returnSelect"].ToString()}";
                
                sc.SCWord = txtExplain.Text.Trim();
                sc.SCarType = $"{Request.Form["carType"].ToString()}";
                sc.SContain = int.Parse(txtModel.Text.Trim());
                sc.SCost = int.Parse(txtMode2.Text.Trim());
                sc.SGoTime =day+= strT +=time += strT +=minute;
                if (LongSortBLL.SAdd(sc)>0)
                {
                    ButRelease.Attributes.Add("onclick", "return confirm('发布成功！');");
                }
                else
                {
                    ButRelease.Attributes.Add("onclick", "return confirm('发布失败！');");
                }
                
            }
            else
            {
                ButRelease.Attributes.Add("onclick", "return confirm('请输入完整信息！');");
            }

        }
        protected void SelectListCity_SelectedIndexChanged(object sender, EventArgs e)
        {
         
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            BasePage page = new BasePage();
            //获取当前用户电话
            string Ph = page.LoginUser.ToString();

        }
    }
}